package org.adream.account.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.adream.account.entity.UserEntity;
import org.adream.account.model.UserInfoModel;
import org.adream.account.model.UserIntegralModel;
import org.adream.account.model.UserRoleResModel;
import org.apache.ibatis.annotations.Param;

@BaseMybatisDao
public interface UserDao {
	
	UserEntity queryUserByUid(@Param("uid") String uid);

	UserEntity queryUserByDrAndUid(@Param("dr") int dr,@Param("uid") String uid);

	List<UserEntity> queryUsersByDr(@Param("dr") int dr);

	List<UserEntity> queryUsersByDrAndSomeLike(@Param("dr") int dr,@Param("uid") String uid,@Param("uname") String uname,
			@Param("phone") String phone,@Param("email") String email,@Param("rleId") String rleId,@Param("order") String order,@Param("realName")String realName);
	
	//组合查询
	List<UserEntity> queryUsersByDrAndRleIdAndInfo(@Param("dr") int dr, @Param("rleId") String rleId, @Param("info") String info, 
			@Param("startCts") Date startCts, @Param("endCts") Date endCts, @Param("order") String order);
	
	UserEntity queryUserByUname(@Param("uname") String uname);
	
	/**
	 * user部分信息 
	 * @param phone
	 * @return
	 */
	UserEntity queryUserByPhone(@Param("phone") String phone);
	
	/**
	 * user部分信息
	 * @param email
	 * @return
	 */
	UserEntity queryUserByEmail(@Param("email") String email);
	
	/**
	 * user全部信息
	 * @param phone
	 * @return
	 */
	UserEntity queryUserEntityByPhone(@Param("phone") String phone);
	
	/**
	 *  若uid 为null 则计数全部昵称数量；
	 *  若uid 不为null 则计数除了uid之外的其他全部数量
	 * @param uname
	 * @param uid
	 * @return
	 */
	int countUserByUname(@Param("uname")String uname,@Param("uid")String uid);
	
	int countUserByPhone(@Param("phone")String phone);
	
	int countUserByEmail(@Param("email")String email);

	int addUser(UserEntity user);

	int deleteUser(UserEntity user);

	int updateUser(UserEntity user);
	
	UserRoleResModel queryUserRoleResByUid(@Param("uid") String uid,@Param("dr") Integer dr);
	
	UserEntity queryUserByUid2(@Param("uid") String uid);
	
	int updateHeadimg(UserEntity user);
	
	int updateBasicInfo(UserEntity user);
	
	String queryMaxUid();

	ArrayList<HashMap<String, Object>> queryUserListByUid(@Param("uid")String uid,@Param("mts")String mts);

	Map<String, Object> queryUserInfoByPhone(String phone);
	
	/**
	 * update 梦想教师角色的  认证-->认证失败
	 * @param uid
	 * @return
	 */
	int rejectTeacherVerifyByUid(String uid);

	List<String> getUserResIdsByUid(String uid);
	
	List<String> getUserRoleIdsByUid(String uid);
	
	int updateRealName(UserEntity user);
	
	//根据微信unionid查询用户
	int countUserByUnionid(@Param("unionid") String unionid);
	
	//更新用户mts
	int updateUserMts(UserEntity user);

	UserEntity searchByUnionid(@Param("unionid")String unionid);
	
	//查询用户基本资料
	UserInfoModel queryUserInfo(@Param("uid") String uid, @Param("dr") Integer dr);
	
	//查询梦想教师用户信息
	List<UserInfoModel> queryTeacherUserInfos(@Param("uids") String[] uids, @Param("dr") Integer dr);
	//包含所有身份的用户信息
	List<UserInfoModel> queryUserInfos(@Param("uids") String[] uids);

	int updateBlackList(@Param("uid")String uid, @Param("blackFlag")Boolean blackFlag);

	int updateUnionid(UserEntity phoneUser);

	int countUserByPhoneAndNotUsedByUnionid(@Param("unionid")String unionid, @Param("phone")String phone);

	int updatePhoneByUid(@Param("uid")String uid, @Param("phone")String phone);

	List<Map<String, Object>> queryUserList(@Param("realName")String realName, @Param("schoolName")String schoolName, @Param("phone")String phone, @Param("rleId")String rleId,
			@Param("province")String province, @Param("city")String city, @Param("area")String area);

	int selectCountByQr(@Param("qr")String qr);

	int updateQr(@Param("uid")String uid, @Param("qr")String qr);

	UserEntity queryUserByQr(@Param("qr")String qr);
	
	//根据学校账号uid,认证状态,角色id,删除标志 查询rle梦想教师 
	List<UserEntity> queryTeacherUsersBySuidAndStateAndRleIdAndDr(@Param("suid") String suid, @Param("state") int state, @Param("rleId") String rleId, @Param("dr") int dr);
	
	//根据学校账号uid,认证状态,删除标志 查询梦想教师
	List<UserEntity> queryTeacherUsersBySuidAndStateAndDr(@Param("suid") String suid, @Param("state") int state, @Param("dr") int dr);

	//根据学校账号uid,用户uid,认证状态,删除标志 查询梦想教师uid是否属于该学校
	UserEntity queryTeacherUserBySuidAndUidAndStateAndDr(@Param("suid") String suid, @Param("uid") String uid, @Param("state") int state, @Param("dr") int dr);

	List<UserEntity> getUserInfoByNameOrPhone(@Param("where")String where);
	
	//查询用户积分
	List<UserIntegralModel> queryUserIntegrals(@Param("uid") String uid, @Param("uname") String uname, @Param("realName") String realName, 
			@Param("phone") String phone, @Param("sname") String sname, @Param("rleIds") List<String> rleIds, @Param("dr") Integer dr);
	
	//根据uid,dr查询用户积分
	UserIntegralModel queryUserIntergralByUidAndDr(@Param("uid") String uid, @Param("dr") Integer dr);
	
	//通过uid更新用户积分
	int updateUserIntegralByUid(UserEntity user);
	
	//更新数据库中空值的性别
	int updateSexByUid(@Param("sex")String sex, @Param("uid")String uid);
	
	//根据uid 组 查询对象组  （查手机号）
	List<Map<String, Object>> getPhonesByUids(@Param("uids")List<String> uids);
	//根据phone 组 查询对象组  （查uid）
	List<Map<String, Object>> getUidsByPhones(@Param("phones")List<String> phones);
	
	Integer getUserIntegralByUid(@Param("uid")String uid);
	
	int updateSexAndUsernameByUid(@Param("uid")String uid, @Param("uname")String uname, @Param("sex")String sex);
	
	List<String> queryUidsByResIdAndDr(@Param("resId") String resId, @Param("dr") int dr);

	Integer queryMaxIntegralByUid(@Param("uid")String uid);
}